using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {
	
	
	public GameObject prefabArrow;
	
	private GameObject cursor;
	
	private int cursorPos = 1;
	
	private int delay = 0;
	
	private int clock = 0;
	
	// Use this for initialization
	void Start () {
		cursor = (GameObject) Instantiate(prefabArrow,new Vector3(-4, -1.8f, 0), Quaternion.identity);
		cursor.transform.Rotate (0f,0f,270f);
	}
	
	// Update is called once per frame
	void Update () {
		
		//clock of idle to repeat opening
		if(clock > 1800){
			Application.LoadLevel("Open");
		}else{
			clock ++;
		}
		
		if(Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Space) ){
			if(cursorPos == 1){
  				Application.LoadLevel("Menu2");
			}
			else if (cursorPos == 2){
				Application.LoadLevel("HowToPlay");
			}
			else if (cursorPos == 3){
				Application.LoadLevel("Credits");
			}		
		}
		
		if(delay > 24){			
			//moving cursor
			if(Input.GetKey(KeyCode.UpArrow)){
				delay = 0;
				clock = 0;
				//print(player.transform.position.y);
				if(cursorPos > 1){
					cursorPos --;
					cursor.transform.Translate ( -1.4f, 0, 0);
				}else{
					//move to last possible position
					cursorPos = 3; //last position number
					cursor.transform.position = new Vector3 (-4, -4.6f, 0); //last position vector
				}
			}
			else if(Input.GetKey(KeyCode.DownArrow)){
				delay = 0;
				clock = 0;
				//print(player.transform.position.y);
				if(cursorPos < 3){ //last position number
					cursorPos ++;
					cursor.transform.Translate ( 1.4f, 0, 0);
				}else{
					//move to first possible position
					cursorPos = 1; //first position number
					cursor.transform.position = new Vector3 (-4, -1.8f, 0); //first position vector
				}
			}			
			
		}else{
			delay ++;
		} 
	 
	}
}
